﻿using DevExpress.Utils;
using MDIDemo.Model;
using MDIDemo.PublicClass;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DevMy.Vou
{
    public partial class Form_Force : Form_ReportBase
    {
        public Form_Force(string FormText)
        {
            InitializeComponent();
            SetComponent(FormText);
        }
        private WaitDialogForm waitDialogForm;
        private Class_MySqlDataBase class_MySqlDataBase;

        private new void SetComponent(string FormText)
        {
            base.SetComponent(FormText, "I0003");
            base.SetGridDataSource(null);
            base.GetGridPage().PageSize = 50;
            base.EnableEditButton(false);
            base.EnableViewButton(false);
            base.EnableOutButton(false);

            Class_PublicMethod class_PublicMethod = new Class_PublicMethod();
            Class_DataBaseConDefault class_DataBaseConDefault = new Class_DataBaseConDefault();
            class_DataBaseConDefault = class_PublicMethod.FromXmlToDefaultValueObject<Class_DataBaseConDefault>("DataBaseDefaultValues");

            class_MySqlDataBase = new Class_MySqlDataBase(class_DataBaseConDefault.dataSourceUrl
                , class_DataBaseConDefault.dataBaseName
                , class_DataBaseConDefault.dataSourceUserName
                , class_DataBaseConDefault.dataSourcePassWord
                , class_DataBaseConDefault.Port);
        }
        public override void Finder(int PageNo)
        {
            waitDialogForm = new WaitDialogForm("正在玩命加载中......", "温馨提示");

            DataSet dataSet = this.GetFinder(PageNo, base.GetGridPage().PageSize, null);
            base.SetGridDataSource(dataSet.Tables[0]);
            base.GetGridPage().SetRowCount(int.Parse(dataSet.Tables[1].Rows[0][0].ToString()));
            waitDialogForm.Close();
        }
        private DataSet GetFinder(int PageNo, int PageSize, string Address)
        {
            string SelectSql = "SELECT *";
            string FormSql = "FROM vou_inidata";
            string WhereSql = null;
            string GroupSql = null;
            string HavingSql = null;
            string OrderSql = @"ORDER BY ip
                ,`port`
                ,address                ,channel
                ,createTime desc";
            string TotalFieldName = "*";

            if (Address != null && Address.Trim().Length > 0)
            {
                WhereSql = string.Format("Where projectName like CONCAT('{0}','%') ", Address.Trim());
            }

            PageSqlModel pageSqlModel = class_MySqlDataBase.GetSql(SelectSql
            , FormSql
            , WhereSql
            , GroupSql
            , HavingSql
            , OrderSql
            , PageNo
            , PageSize
            , TotalFieldName);

            return class_MySqlDataBase.GetPageDataSet(pageSqlModel);
        }


        private void Form_Force_FormClosed(object sender, FormClosedEventArgs e)
        {
            if (waitDialogForm != null)
            {
                waitDialogForm.Dispose();
            }
            class_MySqlDataBase.CloseSqlConnection();
        }
    }
}
